#include "Digdug.h"

Digdug::Digdug(Point& location)
	:Movables(location, RADIUS_OF_MOVABLE, 1, DIGDUG, getDefaultBitmap(DIGDUG_BITMAP)),
	_is_moving(false)
{}

DetectionResult Digdug::collisionCheck(Movable_type position_type) const
{
	switch(position_type)
	{
	case HOLE:
		return CAN_MOVE;
		break;
	case SAND:
		return EAT_SAND;
		break;
	case MONSTER:
		return DIGDUG_DEAD;
		break;
	case DIGDUG:		//Should never happen!
		return DIGDUG_DEAD;
		break;
	}
	return DIGDUG_DEAD;		//Should never reach here!
}

DetectionResult Digdug::move(Map &map)
{
	DetectionResult move_result = CAN_MOVE;
	if (_is_moving)
	{
		move_result = checkMoveInDirection(_location, _direction, map);
		if ( move_result == CAN_MOVE || move_result == EAT_SAND)
		{
			int delta_x = delta(_direction).at(0);
			int delta_y = delta(_direction).at(1);
			_location = Point(_location.x() + delta_x, _location.y() + delta_y);
		}

		_is_moving = false;
	}
	
	return move_result;
}

void Digdug::allowMove(Direction direction)
{
	_direction = direction;
	_is_moving = true;
}
